BEGIN TRANSACTION;
BEGIN TRY
    -- 业务操作
    INSERT INTO Orders (OrderID, CustomerID) VALUES (1001, 'ALFKI');
    UPDATE Inventory SET Stock = Stock - 1 WHERE ProductID = 200;
    COMMIT TRANSACTION;
END TRY
BEGIN CATCH
    IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION; -- 检查事务是否活跃
    SELECT ERROR_MESSAGE() AS ErrorMsg; -- 返回错误信息
END CATCH;
